//
// Created by hamlet on 2021/12/29.
//
#include "tianqidata.h"
#include <QDataStream>
#include <QApplication>

QDataStream& operator<<(QDataStream &out, const TianqiMethod &method) {
    out << static_cast<int>(method);
    return out;
}

QDataStream& operator>>(QDataStream &in, TianqiMethod &method) {
    int m;
    in >> m;
    method = static_cast<TianqiMethod>(m);
    return in;
}

QDataStream& operator<<(QDataStream &out, const MethodHefeng &hefeng) {
    out << hefeng.key << hefeng.location;
    return out;
}

QDataStream& operator>>(QDataStream &in, MethodHefeng &hefeng) {
    in >> hefeng.key >> hefeng.location;
    return in;
}

QDataStream& operator<<(QDataStream &out, const MethodTianqiServer &tianqiServer) {
    out << tianqiServer.webAddress;
    return out;
}

QDataStream& operator>>(QDataStream &in, MethodTianqiServer &tianqiServer) {
    in >> tianqiServer.webAddress;
    return in;
}

QDebug operator<<(QDebug dbg, const TianqiMethod &method) {
    switch (method) {
        case TianqiMethod::Hefeng:
            dbg.nospace() << "和风天气";
            break;
        case TianqiMethod::TianqiServer:
            dbg.nospace() << QApplication::tr("Tianqi Server");
            break;
    }
    return dbg.maybeSpace();
}

QDebug operator<<(QDebug dbg, const MethodHefeng &hefeng) {
    dbg.nospace() << "key=" << hefeng.key << "\nlocation=" << hefeng.location;
    return dbg.maybeSpace();
}

QDebug operator<<(QDebug dbg, const MethodTianqiServer &tianqiServer) {
    dbg.nospace() << "webAddress=" << tianqiServer.webAddress;
    return dbg.maybeSpace();
}
